
// 工具类
var Util = {
    _timer: null,
    showTip: function(str) {
        var dom = $('<div class="f-tips"></div>').text(str),
            old = $('.f-tips');
        if (old.length) {
            old.replaceWith(dom); // replaceWith() 方法用指定的 HTML 内容或元素替换被选元素。
        } else {
            $(document.body).append(dom);
        }
        clearTimeout(this._timer);
        this._time = setTimeout(function() {
            dom.css("opacity", "0").remove();
        }, 2000);
    },

    getQuery: function(name, url) {
        var u = url || location.search,
            reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"),
            r = u.substr(u.indexOf("\?") + 1).match(reg);
        return r != null ? r[2] : "";
    }
}

function isMobile(tel) {
    return /^1\d{10}$/.test(tel);
}

function getCookie(name) {
    var reg = new RegExp("(^| )" + name + "(?:=([^;]*))?(;|$)"),
        val = document.cookie.match(reg);
    return val ? (val[2] ? unescape(val[2]) : "") : null;
}

function setCookie(name, value, expires, path, domain, secure) {
    var exp = new Date(),
        expires = arguments[2] || null,
        path = arguments[3] || "/",
        domain = arguments[4] || null,
        secure = arguments[5] || false;
    expires ? exp.setMinutes(exp.getMinutes() + parseInt(expires)) : "";
    document.cookie = name + '=' + escape(value) + (expires ? ';expires=' + exp.toGMTString() : '') + (path ? ';path=' + path : '') + (domain ? ';domain=' + domain : '') + (secure ? ';secure' : '');
}

function delCookie(name, path, domain, secure) {
    var value = $getCookie(name);
    if (value != null) {
        var exp = new Date();
        exp.setMinutes(exp.getMinutes() - 1000);
        path = path || "/";
        document.cookie = name + '=;expires=' + exp.toGMTString() + (path ? ';path=' + path : '') + (domain ? ';domain=' + domain : '') + (secure ? ';secure' : '');
    }
}

function setCookie1(name, val, iDay) {

    // var str = name + "=" + encodeURIComponent(val);
    var str = name + "=" + val;

    str += ";"

    var oDate = new Date();

    oDate.setDate(oDate.getDate() + iDay);

    str += "expires=" + oDate + ';path=/';

    document.cookie = str;
}

function getCookie1(name) {
    var arr = document.cookie.split("; ");

    for (var i = 0; i < arr.length; i++) {
        
        var arr2 = arr[i].split("=");

        if (arr2[0] == name) {
            return arr2[1];
            // return decodeURIComponent(arr2[1]);
        }
    }

    return "";
}

function removeCookie1(name) {
    setCookie(name, 1, -1);
}

$(function() {
        //用户名显示
        if($('b.success_name').length !=0) {
            var name = getCookie('name');
            $('b.success_name').text(name);   
        }
        //导航条点击事件
         var box = $('div.shop_type_div');
         //shop_type_div鼠标hover事件
         box.mouseenter(function() {
            $(this).find('#sidebar').show();
         });
         box.mouseleave(function() {
            $(this).find('#sidebar').hide();
         });

         var li_nav = $('#sidebar>li');
         li_nav.mouseenter(function(e) {
            if($(this).parent().parent().attr('class') == 'shop_type_div'){
                $('>a',this).addClass('hoverAll');
            }else {
                $('>a',this).addClass('hover');
            }   
            
            $('div.clearfix',this).show();
         })
         li_nav.mouseleave(function(e) {
            $('a',this).removeClass('hover');
            $('a',this).removeClass('hoverAll');
            $('div.clearfix',this).hide();
         });

          //搜索栏事件
        var search = $('#serchWord');
        search.click(function() {
            if(this.value!=null){
                this.value='';
            }
        });
        search.blur(function() {
            if(this.value==''){
                this.value ='多搜搜，意外惊喜等你拿';
            }
        });
})